<?php
namespace App\Http\Controllers\Home;

use App\Http\Controllers\BaseController;
use App\Models\Bmi;
use App\Models\Eton;
use App\Models\Lunar;
use Illuminate\Http\Request;

class HomeController extends  BaseController
{
    public  function homePage (Request $request)
    {
        $userId = $request->get('userId');
        if (!$userId)
        {
            return $this->error('请传入有效的userid');
        }
        $bmiModel = new Bmi();
        $bmiInfo = $bmiModel ->selectMainBmi($userId);
        $name = '';
        if ($bmiInfo)
        {
            $name = $bmiInfo['name'];
        }
        $time = time();
        $year = date('Y',$time);
        $month = date('m',$time);
        $day = date('d',$time);
        $weekarray = array('日','一','二','三','四','五','六');
        $week = '星期' . $weekarray[date('w',$time)];
        $lunar = new Lunar();
        $lunar_array = $lunar->convertSolarMonthToLunar($year,$month,$day);
        $solar = $lunar->getJieQi($year,$month,$day);

        $h = date('H',$time);
        $time_interval = '早上好';
        if ($h < 11)
        {
            $time_interval = '中午好';
        } elseif ($h <13)
        {
            $time_interval = '下午好';
        } else
        {
            $time_interval = '晚上好';
        }

        //医顿
        $eton = new Eton();
        $userEton = $eton->getEtonTotalByUid($userId);
        if ($userEton)
        {
            $data['isEton'] = true;
        }else
        {
            $data['isEton'] = false;
        }
        $data['habitusName'] = "";
        $data['day'] = $day;
        $data['year_month'] = $year . '/' . $month;
        $data['week'] = $week;
        $data['time_interval'] = $time_interval;
        $data['lunar_calendar'] = $lunar_array[0] . $lunar[1];
        $data['name'] = $name;
//        if (substr($solar['name2'], -3) != '后') {
//            $data['solarTerm'] = $solar['name1'];
//        }
        echo $this->success('',$data);



    }
}